package com.hckj.medical.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hckj.medical.entity.Report;
import com.hckj.medical.service.IReportService;
import com.hckj.medical.utils.Code;
import com.hckj.medical.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hckj
 * @since 2023-11-25
 */
@RestController
@RequestMapping("/medical/report")
public class ReportController {
    @Autowired
    private IReportService reportService;

    /**
     * 查询所有就诊报告
     * @param map
     * @return
     */
    @PostMapping("/findall")
    public R findAllByobj(@RequestBody Map map){
        Page<Map> mapPage = reportService.selectAll(map);
        if (mapPage == null){
            return new R(Code.GET_ERRO,"查询失败");
        }else {
            return new R(Code.GET_OK,mapPage,"查询成功");
        }
    }

    /**
     * 添加就诊报告单
     * @param report
     * @return
     */
    @PostMapping("/addReport")
    public R addReport(@RequestBody Report report){
        reportService.insertReport(report);
        return new R(Code.SAVE_OK,"添加成功");
    }

    /**
     * 根据id查询报告单
     * @param id
     * @return
     */
    @GetMapping("/selectByid/{id}")
    public R selectByid(@PathVariable Integer id){
        Report byid = reportService.findByid(id);
        if (byid != null){
            return new R(Code.GET_OK,byid,"查询成功");
        }else {
            return new R(Code.GET_ERRO,"查询失败");
        }
    }
}
